﻿using System;
using System.Text;
using System.Data;
using System.Web;
using JMcms.Common;
using System.Web.SessionState;

namespace JMcms.Web.Plugin.Advert
{
    public class ajax : IHttpHandler, IRequiresSessionState
    {
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            string queryString = JMRequest.GetQueryString("action");
            string a = queryString;
            if (a == "add")
            {
                this.feedback_add(context);
            }
        }
        private void feedback_add(HttpContext context)
        {
            StringBuilder stringBuilder = new StringBuilder();
            JMcms.Web.Plugin.Job.BLL.job_apply job_apply = new JMcms.Web.Plugin.Job.BLL.job_apply();
            JMcms.Web.Plugin.Job.Model.job_apply job_apply2 = new JMcms.Web.Plugin.Job.Model.job_apply();
            string formString = JMRequest.GetFormString("txtCode");
            string formString2 = JMRequest.GetFormString("job_id");
            string formString3 = JMRequest.GetFormString("txtTitle");
            string formString4 = JMRequest.GetFormString("rdioSex");
            string formString5 = JMRequest.GetFormString("txtAge");
            string formString6 = JMRequest.GetFormString("txtEducation");
            string formString7 = JMRequest.GetFormString("txtTel");
            string formString8 = JMRequest.GetFormString("txtEmail");
            string formString9 = JMRequest.GetFormString("txtAddress");
            bool flag = string.IsNullOrEmpty(formString);
            if (flag)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起，请输入验证码！\"}");
            }
            else
            {
                bool flag2 = context.Session["dt_session_code"] == null;
                if (flag2)
                {
                    context.Response.Write("{\"status\":0, \"msg\":\"对不起，验证码已过期！\"}");
                }
                else
                {
                    bool flag3 = formString.ToLower() != context.Session["dt_session_code"].ToString().ToLower();
                    if (flag3)
                    {
                        context.Response.Write("{\"status\":0, \"msg\":\"验证码与系统的不一致！\"}");
                    }
                    else
                    {
                        bool flag4 = string.IsNullOrEmpty(formString9);
                        if (flag4)
                        {
                            context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入现居住地址，方便我们第一时间通知您面试！\"}");
                        }
                        else
                        {
                            job_apply2.title = Utils.DropHTML(formString3);
                            job_apply2.job_id = new int?(Convert.ToInt32(Utils.ToHtml(formString2)));
                            job_apply2.address = Utils.DropHTML(formString9);
                            job_apply2.age = new int?(Convert.ToInt32(Utils.DropHTML(formString5)));
                            job_apply2.education = Utils.DropHTML(formString6);
                            job_apply2.email = Utils.DropHTML(formString8);
                            job_apply2.add_time = DateTime.Now;
                            job_apply2.sex = Utils.DropHTML(formString4);
                            job_apply2.tel = Utils.DropHTML(formString7);
                            bool flag5 = job_apply.Add(job_apply2) > 0;
                            if (flag5)
                            {
                                context.Response.Write("{\"status\": 1, \"msg\": \"恭喜您，简历提交成功！\"}");
                            }
                            else
                            {
                                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
                            }
                        }
                    }
                }
            }
        }
    }
}
